package leetcode100;

import java.util.*;

public class lc029 {
    public static void main(String[] args) {
        String digit = "22";
        new lc029().letterCombinations(digit);
    }

    private static final String[] LETTERS= {
            //0 1  2    3       4     5    6       7     8      9
            "","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"
    };

    public List<String> letterCombinations(String digits) {

        List<String> res = new ArrayList<>();
        if (digits.length()==0) {
            return res;
        }
        back(res,new StringBuffer(),digits,0);
        System.out.println("res: "+res);
        return res;
    }

    public void back(List<String> res,StringBuffer current,String digits,int index) {
        if (digits.length()==index) {
            res.add(current.toString());
            return ;
        }

        char c = digits.charAt(index);
        String letters = LETTERS[c-'0'];

        for (int i = 0; i < letters.length(); i++) {
            current.append(letters.charAt(i));
            back(res,current,digits,index+1);
            current.deleteCharAt(current.length()-1);
        }
    }

}
